import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc= new Scanner(System.in);
        int n=sc.nextInt();
        /*for(int i=0;i<n;i++){
            for(int j=0;j<3;j++){
                a[i][j]=sc.nextInt();
                dp[i][j]=a[i][j];
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < 3; j++) {
                if(i==0&&j>0){ 
                    dp[i][j]=dp[i][j]+dp[i][j-1];
                }
                else if(j==0&&i>0){ 
                    dp[i][j]=dp[i][j]+dp[i-1][j];
                }
                else if(i>0){ 
                    dp[i][j]=dp[i][j]+Math.max(dp[i-1][j],dp[i][j-1]);
                }
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < 3; j++){
                System.out.print(dp[i][j]+"==");
            }
            System.out.println("");
        }
        System.out.println(a[n-1][2]);
        //int m=dp[n-1][2];
        //int end=Math.min(dp[n-1][1], dp[n-2][2])+a[n-1][2];
        //System.out.println(end);*/
        n=sc.nextInt();
        int dp[][][][]=new int[n+1][n+1][n+1][n+1];
        int a[][]=new int [n+1][n+1];
        while(n!=0){
            int b=sc.nextInt();
            int c=sc.nextInt();
            int d=sc.nextInt();
            if(b==0&&c==0&&d==0){
                break;
            }else a[b][c]=d;
        }
        for(int b1=1;b1<n;b1++)
            for(int c1=1;c1<n;c1++)
                for(int b2=1;b2<n;b2++)
                    for(int c2=1;c2<n;c2++){
                        dp[b1][c1][b2][c2]=Math.max(Math.max(dp[b1-1][c1][b2-1][c2], dp[b1-1][c1][b2][c2-1]),Math.max(dp[b1][c1-1][b2-1][c2], dp[b1][c1-1][b2][c2-1]));
                    dp[b1][c1][b2][c2]+=a[b1][c1];
                    if(b1!=c1||c2!=c1){
                        dp[b1][c1][b2][c2]+=a[b2][c2];
                    }
                    }System.out.println(dp[n][n][n][n]);
    

    }
}
